//
//  HomeASProductItemCell.m
//  iOS_Store_V2
//
//  Created by Gary on 26/06/2017.
//  Copyright © 2017 czy. All rights reserved.
//

#import "HomeASProductItemCell.h"
#import "TTSAttchmentNode.h"
#import "UIImageView+TTSWebImage.h"

#define kIconWidth                      40
#define kIconHeight                     40
#define kPaddingForSide                 10

@interface HomeASProductItemCell ()

@property (nonatomic, strong) ASNetworkImageNode                    *imageNode;

@property (nonatomic, strong) ASNetworkImageNode                    *coverImageNode;

@property (nonatomic, strong) ASImageNode                           *iconNode;

@property (nonatomic, strong) ASTextNode                            *storeNameNode;

@property (nonatomic, strong) ASTextNode                            *priceNode;

@property (nonatomic, strong) TTSAttchmentNode                      *productNameNode;

@property (nonatomic, strong) TTSAttchmentNode                      *bottomTags; //底部标签

@property (nonatomic, strong) ASTextNode                            *stateAndViewCountNode;

@property (nonatomic, strong) ASTextNode                            *toLoginNode;

@property (nonatomic, strong) ASTextNode                            *unAuditedNode;

@property (nonatomic, strong) ASDisplayNode                         *sellOutNode;

@property (nonatomic, strong) ASImageNode                           *sellOutImageNode;

@property (nonatomic, strong) ASDisplayNode                         *cellBgNode;

@property (nonatomic, assign) CGFloat                               realyWidth;



@end

@implementation HomeASProductItemCell
@dynamic item;

- (NSString*)imageResize:(NSString*)preurl
                imageUrl:(NSString*)endUrl
                   width:(CGFloat)width
                  height:(CGFloat)height {
    NSInteger width_int = round(width * [UIScreen mainScreen].scale );
    NSInteger height_int = round(height * [UIScreen mainScreen].scale);
    return [NSString stringWithFormat:@"%@%@?x-oss-process=image/resize,w_%@,h_%@",preurl,endUrl,@(width_int),@(height_int)];
}

- (void)initCell {
    [super initCell];
    
    self.dividerNode.hidden = YES;
    
    self.realyWidth = self.item.preferredSize.width - self.item.sectionLeftPadding - self.item.sectionRightPadding;
    
    _cellBgNode = [[ASDisplayNode alloc]init];
    _cellBgNode.backgroundColor = [UIColor whiteColor];
    _cellBgNode.style.preferredSize = CGSizeMake(self.realyWidth, self.item.preferredSize.height);
    [self addSubnode:_cellBgNode];
    
    [self addSubnode:self.imageNode];
//    _imageNode.defaultImage = [UIImage imageNamed:@"tupianjiazaibuchu"];
    _imageNode.backgroundColor = HEX_COLOR(0xf9f9f9);
    NSString *imageUrl = [self imageResize:TT_Global_Photo_Domain
                                                imageUrl:self.item.model.path
                                                   width:kCellWidth
                                                  height:kCellWidth];
    [_imageNode setURL:[NSURL URLWithString:imageUrl]];
    
    if(self.item.model.coverPic.length) {
        [self addSubnode:self.coverImageNode];
        _coverImageNode.defaultImage = nil;
        _coverImageNode.backgroundColor = [UIColor clearColor];
        NSString *coverUrl = [self imageResize:TT_Global_Photo_Domain
                                                         imageUrl:self.item.model.coverPic
                                                            width:kCellWidth
                                                           height:kCellWidth];
        [_coverImageNode setURL:[NSURL URLWithString:coverUrl]];
    }
    
    _iconNode = [[ASImageNode alloc] init];
    _iconNode.image = [UIImage imageNamed:@"GoodLabel_new.png"];
    _iconNode.style.preferredSize = CGSizeMake(kIconWidth, kIconHeight);
    [self addSubnode:_iconNode];
    
    
    
    if (self.item.model.isGoodsNew) {
        _iconNode.hidden = NO;
    }else {
        _iconNode.hidden = YES;
    }
    
    _storeNameNode = [self getTextNode];
    _storeNameNode.backgroundColor = [UIColor clearColor];
    _storeNameNode.textContainerInset = UIEdgeInsetsMake((20 - [UIFont systemFontOfSize:12].lineHeight) / 2, 0, 0, 0);
    _storeNameNode.truncationMode = NSLineBreakByTruncatingTail;
    if (self.item.model.storeName.length) {
        
        NSMutableAttributedString *wholeAttr = [[NSMutableAttributedString alloc] init];
        
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        attch.image = [UIImage imageNamed:@"product_store_pre"];
        attch.bounds = CGRectMake(0, -2, 7, 9);
        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
        [wholeAttr appendAttributedString:string];
        [wholeAttr appendString:@" "];
        NSAttributedString *storeNameAttr = [[NSAttributedString alloc]initWithString:self.item.model.storeName
                                                                           attributes:@{
                                                                                        NSForegroundColorAttributeName :HEX_COLOR(0x666666),
                                                                                        NSFontAttributeName : [UIFont systemFontOfSize:12],
                                                                                        NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)
                                                                                        }];
        [wholeAttr appendAttributedString:storeNameAttr];
        [_storeNameNode addTarget:self action:@selector(onViewClick:) forControlEvents:ASControlNodeEventTouchUpInside];
        _storeNameNode.attributedText = wholeAttr;
    }
    
    [self addSubnode:_storeNameNode];
    
    _productNameNode = [[TTSAttchmentNode alloc]init];
    _productNameNode.maximumNumberOfLines = 2;
    _productNameNode.truncationMode = NSLineBreakByTruncatingTail;
    NSMutableAttributedString *mutableAttr = [[NSMutableAttributedString alloc]init];
    if (self.item.model.name.length) {
        NSAttributedString *productNameAttr = [[NSAttributedString alloc]initWithString:self.item.model.name
                                                                             attributes:@{
                                                                                          NSForegroundColorAttributeName :HEX_COLOR(0x333333),
                                                                                          NSFontAttributeName:[UIFont systemFontOfSize:14]
                                                                                          }];
        [mutableAttr appendAttributedString:productNameAttr];
    }
    _productNameNode.attributedText = mutableAttr;
    NSMutableArray *topTagArrays = [[NSMutableArray alloc]init];
    for (NSString * string in self.item.model.goodsTagsTop) {
        NSString *imageString = [NSString stringWithFormat:@"%@%@",TT_Global_Photo_Domain,string];
        imageString = [imageString tts_webImagePathWithHeight:14];
        [topTagArrays addObject:imageString];
    }
    if (topTagArrays.count) {
        [_productNameNode setImages:topTagArrays text:self.item.model.name textAttrDic:@{
                                                                                         NSForegroundColorAttributeName :HEX_COLOR(0x666666),
                                                                                         NSFontAttributeName:[UIFont systemFontOfSize:14]
                                                                                         }];
    }
    
    
    [self addSubnode:_productNameNode];
    
    _bottomTags = [[TTSAttchmentNode alloc]init];
    NSMutableArray *bottomTagArrays = [[NSMutableArray alloc]init];
    for (NSString * string in self.item.model.goodsTagsBottom) {
        NSString *imageString = [NSString stringWithFormat:@"%@%@",TT_Global_Photo_Domain,string];
//        imageString = [imageString tts_webImagePathWithHeight:12];
        [bottomTagArrays addObject:imageString];
    }
    if (bottomTagArrays.count) {
        [_bottomTags setImages:bottomTagArrays text:@" " textAttrDic:@{
                                                                       NSForegroundColorAttributeName :[UIColor clearColor],
                                                                       NSFontAttributeName:[UIFont systemFontOfSize:12]
                                                                       }];
    }
    
    [self addSubnode:_bottomTags];
    
    [self loadPriceAndStateWithNewType];
    
    if (!self.item.model.inventory.integerValue) {
        _sellOutNode = [[ASDisplayNode alloc]init];
        _sellOutNode.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
        _sellOutNode.style.preferredSize = CGSizeMake(self.realyWidth, self.realyWidth);
        [self addSubnode:_sellOutNode];
        
        [self addSubnode:self.sellOutImageNode];
        
    }
    
    
    
    
    
}

- (void)didLoad {
    [super didLoad];
    
//    _stateAndViewCountNode.layer.borderWidth = 1;
//    _toLoginNode.layer.borderWidth = 1;
//    _storeNameNode.layer.borderWidth = 1;
//    _priceNode.layer.borderWidth = 1;
//    _bottomTags.layer.borderWidth = 1;
//    _productNameNode.layer.borderWidth = 1;
    
    _cellBgNode.layer.cornerRadius = 7;
   
    
}

- (ASLayoutSpec*)layoutSpecThatFits:(ASSizeRange)constrainedSize {
    

    ASOverlayLayoutSpec *backSpcer = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_imageNode overlay:_iconNode];
    NSMutableArray *mutableArray = [[NSMutableArray alloc]init];
    if(_coverImageNode) {
        ASBackgroundLayoutSpec *coverBackSpec = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:_coverImageNode background:backSpcer];
        [mutableArray addObject:coverBackSpec];
    }else {
        [mutableArray addObject:backSpcer];
    }
    [mutableArray addObject:_productNameNode];
    ASStackLayoutSpec *stackSpcer = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
                                                                            spacing:5
                                                                     justifyContent:ASStackLayoutJustifyContentStart
                                                                         alignItems:ASStackLayoutAlignItemsStart
                                                                           children:mutableArray];
    
    ASDisplayNode *btnNode = nil;
    if (self.item.model.pType == 6) {
        btnNode = _toLoginNode;
    }else if (self.item.model.pType == 7) {
        btnNode = _unAuditedNode;
    }else {
        btnNode = _priceNode;

    }
    
    ASStackLayoutSpec *bottomStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
                                                                             spacing:8
                                                                      justifyContent:ASStackLayoutJustifyContentStart
                                                                          alignItems:ASStackLayoutAlignItemsStart
                                                                            children:@[_bottomTags,btnNode,_storeNameNode,_stateAndViewCountNode]];
    ASStackLayoutSpec *wholeSpcer = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
                                                                            spacing:5
                                                                     justifyContent:ASStackLayoutJustifyContentStart
                                                                         alignItems:ASStackLayoutAlignItemsStart
                                                                           children:@[stackSpcer,bottomStack]];
    ASBackgroundLayoutSpec *wholeBackSpecer = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:_cellBgNode background:wholeSpcer];
    return wholeBackSpecer;

}

- (void)layout {
    [super layout];
    
    
    _cellBgNode.frame = CGRectMake(self.item.sectionLeftPadding, 5, self.realyWidth, self.item.preferredSize.height - 5);
    
    _imageNode.frame = CGRectMake(self.item.sectionLeftPadding, 5, self.realyWidth , self.realyWidth);
    if(_coverImageNode) {
        _coverImageNode.frame = CGRectMake(self.item.sectionLeftPadding, 5, self.realyWidth, self.realyWidth);
    }
    if (!_iconNode.hidden) {
        _iconNode.frame = CGRectMake(_imageNode.frame.size.width + _imageNode.frame.origin.x - kIconWidth, _imageNode.frame.origin.y, kIconWidth, kIconHeight);
    }

    _productNameNode.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, self.realyWidth + 10, self.realyWidth - kPaddingForSide * 2, 34);
    _bottomTags.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, _productNameNode.frame.origin.y + _productNameNode.frame.size.height + 8, _bottomTags.calculatedSize.width, _bottomTags.calculatedSize.height);
    if (self.item.model.pType == 6) {
        
        _toLoginNode.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, _bottomTags.frame.origin.y + _bottomTags.frame.size.height , self.realyWidth - kPaddingForSide * 2, 30);
        _storeNameNode.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, _toLoginNode.frame.origin.y + _toLoginNode.frame.size.height + 0, self.realyWidth - kPaddingForSide * 2, 20);

        
        
    }else if (self.item.model.pType == 7) {
        _unAuditedNode.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, _bottomTags.frame.origin.y + _bottomTags.frame.size.height  , self.realyWidth - kPaddingForSide * 2, 30);
        _storeNameNode.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, _unAuditedNode.frame.origin.y + _unAuditedNode.frame.size.height + 0 , self.realyWidth - kPaddingForSide * 2, 20);

    }else {
        
        _priceNode.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, _bottomTags.frame.origin.y + _bottomTags.frame.size.height , self.realyWidth - kPaddingForSide * 2, 30);
        _storeNameNode.frame = CGRectMake(kPaddingForSide + self.item.sectionLeftPadding, _priceNode.frame.origin.y + _priceNode.frame.size.height + 0, self.realyWidth - kPaddingForSide * 2, 20);

    }
    
    
    _stateAndViewCountNode.frame = CGRectMake( kPaddingForSide + self.item.sectionLeftPadding , _storeNameNode.frame.origin.y + _storeNameNode.frame.size.height + 10, _stateAndViewCountNode.calculatedSize.width, _stateAndViewCountNode.calculatedSize.height);
    
    if (!self.item.model.inventory.integerValue) {
        _sellOutNode.frame = CGRectMake(0 + self.item.sectionLeftPadding, 5, self.realyWidth, self.realyWidth);
        _sellOutImageNode.frame = CGRectMake((_sellOutNode.frame.size.width - _sellOutImageNode.style.preferredSize.width) / 2 + self.item.sectionLeftPadding, (_sellOutNode.frame.size.height - _sellOutImageNode.style.preferredSize.height) / 2, _sellOutImageNode.style.preferredSize.width, _sellOutImageNode.style.preferredSize.height);
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_sellOutNode.view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(7, 7)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = _sellOutNode.view.bounds;
        maskLayer.path = maskPath.CGPath;
        _sellOutNode.view.layer.mask = maskLayer;
    }
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_imageNode.view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(7, 7)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _imageNode.view.bounds;
    maskLayer.path = maskPath.CGPath;
    _imageNode.view.layer.mask = maskLayer;
    
    
    
}


#pragma mark - Pricate Action

- (void)loadPriceAndStateWithNewType {
    //1.批发价 2.活动价 3.vip1 4.vip2  5.vip3 6.未登录  7.未审核
    NSString *vipStr = @"";
    if (self.item.model.pType == 3) {
        vipStr = @"gd_vip_1";
    }else if (self.item.model.pType == 4) {
        vipStr = @"gd_vip_2";
    }else if (self.item.model.pType == 5) {
        vipStr = @"gd_vip_3";
    }
    switch (self.item.model.pType) {
        case 1:{
            _priceNode = [self getTextNode];
            _priceNode.textContainerInset = UIEdgeInsetsMake((30 - [UIFont systemFontOfSize:18].lineHeight) / 2, 0, 0, 0);
            _stateAndViewCountNode = [self getTextNode];
            [self addSubnode:_priceNode];
            [self addSubnode:_stateAndViewCountNode];
            
            NSString *priceStr = [NSString stringWithFormat:@"¥ %@",self.item.model.pValue];
            NSMutableAttributedString *attr_string = [[NSMutableAttributedString alloc]initWithString:priceStr];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont systemFontOfSize:12],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         } range:NSMakeRange(0, 1)];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Medium" size:18],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         }range:NSMakeRange(1, priceStr.length - 3)];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont systemFontOfSize:12],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         }range:NSMakeRange(priceStr.length - 2, 2)];
            _priceNode.attributedText = attr_string;
            
            
            if (self.item.model.viewCount.length) {
                NSString *viewCount = [NSString stringWithFormat:@"%@次浏览量",self.item.model.viewCount];
                
                NSAttributedString *viewCountAttr = [[NSAttributedString alloc]initWithString:viewCount
                                                                                   attributes:@{
                                                                                                NSForegroundColorAttributeName : HEX_COLOR(0x999999),
                                                                                                NSFontAttributeName :[UIFont systemFontOfSize:12]
                                                                                                }];
                _stateAndViewCountNode.attributedText = viewCountAttr;
            }
            
            break;
        }
        case 2:{
            _priceNode = [self getTextNode];
            _priceNode.textContainerInset = UIEdgeInsetsMake((30 - [UIFont systemFontOfSize:18].lineHeight) / 2, 0, 0, 0);
            _stateAndViewCountNode = [self getTextNode];
            [self addSubnode:_priceNode];
            [self addSubnode:_stateAndViewCountNode];
            
            
            NSMutableAttributedString *priceMutableAttr = [[NSMutableAttributedString alloc]init];
            NSTextAttachment *attch = [[NSTextAttachment alloc] init];
            attch.image = [UIImage imageNamed:@"activityPeiceTag.png"];
            attch.bounds = CGRectMake(0, -2, 33, 13);
            NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
            [priceMutableAttr appendAttributedString:string];
            [priceMutableAttr appendString:@" "];
            NSString *priceStr = [NSString stringWithFormat:@"¥ %@",self.item.model.pValue];
            NSMutableAttributedString *attr_string = [[NSMutableAttributedString alloc]initWithString:priceStr];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont systemFontOfSize:12],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         } range:NSMakeRange(0, 1)];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Medium" size:18],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         }range:NSMakeRange(1, priceStr.length - 3)];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont systemFontOfSize:12],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         }range:NSMakeRange(priceStr.length - 2, 2)];
            [priceMutableAttr appendAttributedString:attr_string];
            _priceNode.attributedText = priceMutableAttr;
            
            

            NSMutableAttributedString *mutableAttr = [[NSMutableAttributedString alloc]init];
            if (self.item.model.viewCount.length) {
                NSAttributedString *viewConteAttr = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@次浏览量",self.item.model.viewCount]
                                                                                   attributes:@{
                                                                                                NSFontAttributeName : [UIFont systemFontOfSize:12],
                                                                                                NSForegroundColorAttributeName : HEX_COLOR(0x999999)
                                                                                                }];
                [mutableAttr appendAttributedString:viewConteAttr];
            }
            _stateAndViewCountNode.attributedText = mutableAttr;
            
            break;
        }
        case 3:
        case 4:
        case 5: {
            _priceNode = [self getTextNode];
            _priceNode.textContainerInset = UIEdgeInsetsMake((30 - [UIFont systemFontOfSize:18].lineHeight) / 2, 0, 0, 0);
            _stateAndViewCountNode = [self getTextNode];
            [self addSubnode:_priceNode];
            [self addSubnode:_stateAndViewCountNode];
            NSMutableAttributedString *priceMutableAttr = [[NSMutableAttributedString alloc]init];
            NSTextAttachment *attch = [[NSTextAttachment alloc] init];
            attch.image = [UIImage imageNamed:vipStr];
            attch.bounds = CGRectMake(0, -2, 19, 14);
            NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
            [priceMutableAttr appendAttributedString:string];
            NSAttributedString *attrSpace = [[NSAttributedString alloc] initWithString:@" "
                                                                            attributes:@{
                                                                                         NSForegroundColorAttributeName :[UIColor whiteColor],
                                                                                         NSFontAttributeName : [UIFont systemFontOfSize:12],
                                                                                         }];
            [priceMutableAttr appendAttributedString:attrSpace];
            NSString *priceStr = [NSString stringWithFormat:@"¥%@",self.item.model.pValue];
            NSMutableAttributedString *attr_string = [[NSMutableAttributedString alloc]initWithString:priceStr];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont systemFontOfSize:12],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         } range:NSMakeRange(0, 1)];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Medium" size:18],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         }range:NSMakeRange(1, priceStr.length - 3)];
            [attr_string addAttributes:@{
                                         NSFontAttributeName : [UIFont systemFontOfSize:12],
                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e)
                                         }range:NSMakeRange(priceStr.length - 2, 2)];
            [priceMutableAttr appendAttributedString:attr_string];
            _priceNode.attributedText = priceMutableAttr;
            
            
            
            NSMutableAttributedString *mutableAttr = [[NSMutableAttributedString alloc]init];
            if (self.item.model.viewCount.length) {
                NSAttributedString *viewConteAttr = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@" %@次浏览量",self.item.model.viewCount]
                                                                                   attributes:@{
                                                                                                NSFontAttributeName : [UIFont systemFontOfSize:12],
                                                                                                NSForegroundColorAttributeName : HEX_COLOR(0x999999)
                                                                                                }];
                [mutableAttr appendAttributedString:viewConteAttr];
            }
            _stateAndViewCountNode.attributedText = mutableAttr;
            
            
            break;
        }
        case 6: {
            
            _toLoginNode = [self getTextNode];
            _toLoginNode.textContainerInset = UIEdgeInsetsMake((30 - [UIFont systemFontOfSize:13].lineHeight) / 2, 0, 0, 0);
            [self addSubnode:_toLoginNode];
            _stateAndViewCountNode = [self getTextNode];
            [self addSubnode:_stateAndViewCountNode];
            
            NSAttributedString *toLoginAttr = [[NSAttributedString alloc]initWithString:@"登录后查看价格"
                                                                             attributes:@{
                                                                                          NSForegroundColorAttributeName : HEX_COLOR(0xff434e),
                                                                                          NSFontAttributeName : [UIFont systemFontOfSize:13]
                                                                                          }];
            _toLoginNode.attributedText = toLoginAttr;
            [_toLoginNode addTarget:self action:@selector(onViewClick:) forControlEvents:ASControlNodeEventTouchUpInside];
            
            
            if (self.item.model.viewCount.length) {
                NSString *viewCount = [NSString stringWithFormat:@"%@次浏览量",self.item.model.viewCount];
                
                NSAttributedString *viewCountAttr = [[NSAttributedString alloc]initWithString:viewCount
                                                                                   attributes:@{
                                                                                                NSForegroundColorAttributeName : HEX_COLOR(0x999999),
                                                                                                NSFontAttributeName :[UIFont systemFontOfSize:12]
                                                                                                }];
                _stateAndViewCountNode.attributedText = viewCountAttr;
            }
            break;
        }
        case 7:{
            
            _unAuditedNode = [self getTextNode];
            [self addSubnode:_unAuditedNode];
            _stateAndViewCountNode = [self getTextNode];
            [self addSubnode:_stateAndViewCountNode];
            
            NSAttributedString *auditeAttr = [[NSAttributedString alloc]initWithString:@"通过审核后查看价格"
                                                                            attributes:@{
                                                                                         NSForegroundColorAttributeName : HEX_COLOR(0xff434e),
                                                                                         NSFontAttributeName : [UIFont systemFontOfSize:13]
                                                                                         }];
            _unAuditedNode.attributedText = auditeAttr;
            
            if (self.item.model.viewCount.length) {
                NSString *viewCount = [NSString stringWithFormat:@"%@次浏览量",self.item.model.viewCount];
                
                NSAttributedString *viewCountAttr = [[NSAttributedString alloc]initWithString:viewCount
                                                                                   attributes:@{
                                                                                                NSForegroundColorAttributeName : HEX_COLOR(0x999999),
                                                                                                NSFontAttributeName :[UIFont systemFontOfSize:12]
                                                                                                }];
                _stateAndViewCountNode.attributedText = viewCountAttr;
            }
            break;
        }
            
            
        default: {
            _priceNode = [self getTextNode];
            _stateAndViewCountNode = [self getTextNode];
            [self addSubnode:_priceNode];
            [self addSubnode:_stateAndViewCountNode];
            break;
        }
            
    }
}



#pragma mark - Private Action

- (void)onViewClick:(id)sender {
    
//    if (self.item.onViewClickHandler) {
//        if (sender == _storeNameNode) {
//            self.item.onViewClickHandler(self.item, ViewActionTypeProductListStoreNameClick);
//        }else {
//            self.item.onViewClickHandler(self.item, ViewActionTypeLogin);
//        }
//
//    }
}



#pragma mark - Create View

- (ASNetworkImageNode*)imageNode {
    if (!_imageNode) {
        _imageNode = [[ASNetworkImageNode alloc]init];
        _imageNode.contentMode = UIViewContentModeScaleAspectFit;
        _imageNode.clipsToBounds = YES;
        _imageNode.style.preferredSize = CGSizeMake(self.realyWidth, self.realyWidth);
    }
    return _imageNode;
}

- (ASNetworkImageNode*)coverImageNode {
    if(!_coverImageNode) {
        _coverImageNode = [[ASNetworkImageNode alloc]init];
        _coverImageNode.contentMode = UIViewContentModeScaleAspectFit;
        _coverImageNode.clipsToBounds = YES;
        _coverImageNode.style.preferredSize = CGSizeMake(self.realyWidth, self.realyWidth);
    }
    return _coverImageNode;
}

- (ASTextNode*)getTextNode {
    ASTextNode *textNode = [[ASTextNode alloc]init];
    textNode.maximumNumberOfLines = 1;
    return textNode;
}

- (ASImageNode*)sellOutImageNode {
    if (!_sellOutImageNode) {
        _sellOutImageNode = [[ASImageNode alloc]init];
        _sellOutImageNode.image = [UIImage imageNamed:@"classify_icon_SoldOut1.png"];
        _sellOutImageNode.style.preferredSize = CGSizeMake(80, 80);
    }
    return _sellOutImageNode;
}

@end
